// Internal action code for project skygarden

package math;

import jason.asSemantics.*;
import jason.asSyntax.*;
import jason.environment.grid.Location;

@SuppressWarnings("serial")
public class distance extends DefaultInternalAction {

    @Override
    public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    	try {
            int iagx = (int) ((NumberTerm) args[0]).solve();
            int iagy = (int) ((NumberTerm) args[1]).solve();
            int itox = (int) ((NumberTerm) args[2]).solve();
            int itoy = (int) ((NumberTerm) args[3]).solve();
            int dist = new Location(iagx, iagy).distance(new Location(itox, itoy));
            return un.unifies(args[4], new NumberTermImpl(dist));
        } catch (Throwable e) {
            e.printStackTrace();
            return false;
        }
    }
}
